package com.cz.datafetcher.controller;

import com.cz.datafetcher.common.SysError;
import com.cz.datafetcher.entity.FetchData;
import com.cz.datafetcher.entity.PostEntity;
import com.cz.datafetcher.service.FetchDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/fetchData")
@Api(tags = "数据采集")
public class FetchDataController {

    @Autowired
    FetchDataService fetchDataService;

    @GetMapping("/fetch")
    @ApiOperation("采集数据")
    public HashMap<String, List<FetchData>> Fetch(String fetchDeviceIds,
                                                  @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date begin,
                                                  @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end,
                                                  boolean save2db){
        return fetchDataService.Fetch(fetchDeviceIds,begin,end,save2db);
    }

    @PostMapping("/postGateway")
    @ApiOperation("数据推送")
    public void PostGateway(@RequestBody PostEntity entity) throws SysError {
        fetchDataService.SavePostValue(entity);
    }
}
